package com.mftour.moudles.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.mftour.common.Constant;
import com.mftour.moudles.entity.ConsoleLog;
import com.mftour.moudles.service.ConsoleLogService;
import com.mftour.moudles.vo.AjaxResponse;
import com.mftour.moudles.vo.ShowPage;
import com.mftour.moudles.vo.search.SearchConsoleLogPagingVo;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
 * This class was generated by Bill Generator. This class corresponds to the
 * database table logs 日志
 *
 * @mbggenerated 2017-33-18 09:33
 */
@Controller
@RequestMapping(value = "/consoleLog")
public class ConsoleLogController extends BaseController {
	@Autowired
	ConsoleLogService consoleLogSer;

	@RequestMapping(value = "/ajax/list", method = RequestMethod.POST)
	@ResponseBody
	@ApiOperation(value = "根据条件获取日志列表", notes = "返回日志列表")
	public ShowPage getConsoleLogList(SearchConsoleLogPagingVo searchConsoleLogPagingVo) {
		List<ConsoleLog> consoleLogList = consoleLogSer.selectListSelectivePaging(searchConsoleLogPagingVo);
		ShowPage page = new ShowPage(searchConsoleLogPagingVo, consoleLogList);
		return page;
	}

	@RequestMapping(value = "/list", method = RequestMethod.GET)
	@ApiOperation(value = "根据条件获取日志列表", notes = "返回日志列表")
	public ModelAndView toConsoleLogList(SearchConsoleLogPagingVo searchConsoleLogPagingVo) {
		ModelAndView mv = new ModelAndView("system/consoleLogList");
		List<ConsoleLog> consoleLogList = consoleLogSer.selectListSelectivePaging(searchConsoleLogPagingVo);
		ShowPage page = new ShowPage(searchConsoleLogPagingVo, consoleLogList);
		mv.addObject("page", page);
		mv.addObject("searchConsoleLogPagingVo", searchConsoleLogPagingVo);
		return mv;
	}

	@RequestMapping(value = "/ajax/save", method = RequestMethod.POST)
	@ResponseBody
	@ApiOperation(value = "新增日志", notes = "新增日志")
	@ApiImplicitParams(value = { @ApiImplicitParam(required = false, name = "id", paramType = "query") })
	public AjaxResponse<ConsoleLog> save(ConsoleLog consoleLog) {
		consoleLog.setId(null);
		AjaxResponse<ConsoleLog> ajaxResponse = new AjaxResponse<ConsoleLog>(Constant.RS_CODE_ERROR, "添加日志出错！");

		consoleLogSer.insertSelective(consoleLog);
		ajaxResponse.setCode(Constant.RS_CODE_SUCCESS);
		ajaxResponse.setMsg("添加日志成功！");
		return ajaxResponse;
	}

	@RequestMapping(value = "/ajax/del", method = RequestMethod.POST)
	@ResponseBody
	@ApiOperation(value = "根据pk删除日志", notes = "根据删除日志")
	@ApiImplicitParams(value = { @ApiImplicitParam(required = true, name = "id", value = "pk", paramType = "query") })
	public AjaxResponse<Object> del(Integer id) {
		AjaxResponse<Object> ajaxResponse = new AjaxResponse<Object>(Constant.RS_CODE_ERROR, "pk不能为null！");
		if (id == null) {
			return ajaxResponse;
		}

		consoleLogSer.deleteByPrimaryKey(id);
		ajaxResponse.setCode(Constant.RS_CODE_SUCCESS);
		ajaxResponse.setMsg("删除日志成功！");
		return ajaxResponse;
	}

	@RequestMapping(value = "/ajax/delAll", method = RequestMethod.POST)
	@ResponseBody
	@ApiOperation(value = "根据pk集合删除日志", notes = "根据pk集合删除日志，以','为分隔符")
	@ApiImplicitParams(value = {
			@ApiImplicitParam(required = true, name = "ids", value = "pk集合", paramType = "query", allowMultiple = true, dataType = "Integer") })
	public AjaxResponse<Object> delAll(Integer[] ids) {
		AjaxResponse<Object> ajaxResponse = new AjaxResponse<Object>(Constant.RS_CODE_ERROR, "请选择删除项！");
		if (ids == null || ids.length < 0) {
			return ajaxResponse;
		}

		consoleLogSer.deleteByPKs(ids);
		ajaxResponse.setCode(Constant.RS_CODE_SUCCESS);
		ajaxResponse.setMsg("删除日志成功!");
		return ajaxResponse;
	}

	@RequestMapping(value = "/ajax/update", method = RequestMethod.POST)
	@ResponseBody
	@ApiOperation(value = "根据pk更新日志", notes = "根据pk更新日志，属性为null的不更新")
	public AjaxResponse<Object> update(ConsoleLog consoleLog) {
		if (consoleLog.getId() == null) {
			return new AjaxResponse<Object>(Constant.RS_CODE_ERROR, "请设置pk！");
		}
		AjaxResponse<Object> ajaxResponse = new AjaxResponse<Object>(Constant.RS_CODE_ERROR, "修改日志出错！");

		consoleLogSer.updateByPrimaryKeySelective(consoleLog);
		ajaxResponse.setCode(Constant.RS_CODE_SUCCESS);
		ajaxResponse.setMsg("修改日志成功！");
		return ajaxResponse;
	}

	@RequestMapping(value = "/ajax/entity", method = RequestMethod.GET)
	@ResponseBody
	@ApiOperation(value = "根据pk获取日志", notes = "根据pk获取日志")
	public AjaxResponse<ConsoleLog> getEntity(Integer id) {
		if (id == null) {
			return new AjaxResponse<ConsoleLog>(Constant.RS_CODE_ERROR, "请选择pk！");
		}
		ConsoleLog consoleLog = consoleLogSer.selectByPrimaryKey(id);
		AjaxResponse<ConsoleLog> ajaxResponse = new AjaxResponse<ConsoleLog>(Constant.RS_CODE_SUCCESS, "获取日志成功！");
		if (consoleLog != null) {
			ajaxResponse.setData(consoleLog);
		} else {
			ajaxResponse.setCode(Constant.RS_CODE_ERROR);
			ajaxResponse.setMsg("获取日志失败！");
		}
		return ajaxResponse;
	}
}